package syn;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * Remarks:CopyOnWriteArrayList 是一个线程安全的，ArrayList是线程不安全的
 *
 * Class name :UC
 * Date :2023/2/15 13:45
 * Author:杨俊源
 */
public class UC {
    public static void main(String[] args) {
        CopyOnWriteArrayList<String > list = new CopyOnWriteArrayList<>();
        for (int i = 0; i < 10000; i++) {
            new Thread(()->{
               list.add(Thread.currentThread().getName());
            }).start();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("list = " + list.size());
    }
}
